package com.yan.furns.service.impl;

import com.yan.furns.dao.FurnDAO;
import com.yan.furns.dao.impl.FurnDAOImpl;
import com.yan.furns.entity.Furn;
import com.yan.furns.entity.Page;
import com.yan.furns.service.FurnService;

import java.util.List;

/**
 * @author Yzb
 * @version 1.0
 */
public class FurnServiceImpl implements FurnService {
	FurnDAO furnDAO = new FurnDAOImpl();

	@Override
	public List<Furn> queryFurns() {
		return furnDAO.queryFurns();
	}

	@Override
	public int insertFurn(Furn furn) {
		return furnDAO.insertFurn(furn);
	}

	@Override
	public int deleteFurn(int id) {
		return furnDAO.deleteFurn(id);
	}

	@Override
	public Furn queryFurn(int id) {
		return furnDAO.queryFurnById(id);
	}

	@Override
	public int updateFurn(Furn furn) {
		return furnDAO.updateFurn(furn);
	}

	@Override
	public Page<Furn> queryFurnPage(int pageNo, int pageSize) {
		Page<Furn> page = new Page<>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		page.setElems(furnDAO.pageQueryFurn((pageNo - 1) * pageSize, pageSize));
		int totalRow = furnDAO.queryTotalFurns();
		page.setTotalRow(totalRow);
		page.setPageTotalCount((totalRow + pageSize - 1) / pageSize);
		page.setUrl("");
		return page;
	}

	@Override
	public Page<Furn> queryFurnPageByName(int pageNo, int pageSize, String name) {
		Page<Furn> page = new Page<>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		page.setElems(furnDAO.pageQueryFurnByName(name, (pageNo - 1) * pageSize, pageSize));
		int totalRow = furnDAO.queryTotalFurnsByName(name);
		page.setTotalRow(totalRow);
		page.setPageTotalCount((totalRow + pageSize - 1) / pageSize);
		page.setUrl("");
		return page;
	}
}
